$(function() {

//新增按钮
    $("#pop_app_btn").click(function(){
        var appId = $("#pop_appid");
        var appName = $("#pop_appname");
        var appDesc = $("#pop_app_desc");

        $.ajax({
            url:base_url+"/app/addApp",
            type:"post",
            data:{
                "appId":appId.val(),
                "appName":appName.val(),
                "appIntroduction":appDesc.val()
            },
            success:function(data){
                if(data.code == SUCCESS_CODE){
                    appId.val("");
                    appName.val("");
                    appDesc.val("");
                    successMsgShow(data.message);
                    setTimeout(function () {
                        window.location.reload();
                    }, 2000);
                }else{
                    warnMsgShow(data.message);
                }

            }
        })
    });

});


//删除功能
var deleteId;
var deleteAppId;
var deleteAppName;
function appDelete(id, appId, appName) {
    deleteMsgShow("【"+appId+":"+appName+"】系统");
    deleteId = id;
    deleteAppId=appId;
    deleteAppName=appName;
}

$("#delete-confirm").click(function () {
    $.ajax({
        url:base_url+"/app/deleteApp",
        type:"post",
        data:{
            "id":deleteId,
            "appId":deleteAppId,
            "appName":deleteAppName,
        },
        success:function(data){
            deleteId=-1
            if(data.code == SUCCESS_CODE){
                successMsgShow(data.message);
                setTimeout(function () {
                    window.location.reload();
                }, 2000);
            }else{
                warnMsgShow(data.message);
            }
        }
    })
});

//删除

//更新
function appModify(id, appId, appName, appIntroduction) {
    $("#pop_modify_appid").val(appId);
    $("#pop_modify_appname").val(appName);
    $("#pop_modify_app_desc").val(appIntroduction);
    $("#pop_modify_id").val(id);
    $("#btn_update").click();
}

$("#pop_modify_app_btn").click(function () {
    var appId = $("#pop_modify_appid").val();
    var appName = $("#pop_modify_appname").val();
    var appDesc = $("#pop_modify_app_desc").val();
    var id = $("#pop_modify_id").val();
    $.ajax({
        url:base_url+"/app/updateApp",
        type:"post",
        data:{
            "id":id,
            "appId":appId,
            "appName":appName,
            "appIntroduction":appDesc,
        },
        success:function(data){
            if(data.code == SUCCESS_CODE){
                successMsgShow(data.message);
                setTimeout(function () {
                    window.location.reload();
                }, 2000);
            }else{
                warnMsgShow(data.message);
            }
            $("#pop_modify_appid").val("");
            $("#pop_modify_appname").val("");
            $("#pop_modify_app_desc").val("");
            $("#pop_modify_id").val("");
        }
    })
})